package minijvm.engine;

import minijvm.loader.ClassFileLoader;

/**
 * @author ChangLiang
 * @date 2020/4/28
 */
public class MiniJVM {

    public void run(String[] classPaths, String className) {
        // init ClassFileLoader and then addClassPath
        ClassFileLoader loader = new ClassFileLoader();
        for (int i = 0; i < classPaths.length; i++) {
            loader.addClassPath(classPaths[i]);
        }

        // init MethodArea
        MethodArea methodArea = MethodArea.getInstance();
        // put classloader into methodarea
        methodArea.setClzLoader(loader);

        // init ExecutorEngine
        ExecutorEngine engine = new ExecutorEngine();

        className = className.replace(".", "/");
        // ExecutorEngine execute methodArea's parsed clzFile's main method
        engine.execute(methodArea.getMainMethod(className));
    }
}
